<!DOCTYPE html>
<html>
<head>
    <include file="Include:meta"/>
    <title>添加项目收款-目的地运营集团数据管理平台</title>
    <include file="Include:style"/>
    <style>
        .w50 {
            width: 50px;
        }
    </style>
</head>
<body>
<include file="Include:header"/>
<include file="Include:left"/>
<div id="main">
    <div class="crumbs">
        <div class="crumbs-text">项目款项列表 > 添加项目收款</div>
    </div>
    <div id="content">
        <form action="__APP__/ContractBack/add_receipt_data" onsubmit="return verify()" method="post" id="project_add_form">
            <input type="hidden" name="contract_id" value="{$res['contract_id']}">
            <input type="hidden" name="back_id" value="{$res['back_id']}">
            <div class="form-main">
                <div class="form-title">添加项目收款</div>
                <div class="form-item">
                    <div class="input-label"><span class="asterisk">*</span>项目编号-名称</div>
                    <div class="input-item">
                        {$res['project_num']}-{$res['name']}
                        <input name="project_id" value="{$res['project_id']}" type="hidden">
                        <span class="error-item">必填项</span>
                    </div>
                </div>
                <div class="form-item">
                    <div class="input-label">合同金额</div>
                    <div class="input-item ht_money">
                        {$res['contract_money']}
                    </div>
                </div>
                <div class="form-item">
                    <div class="input-label">合同日期</div>
                    <div class="input-item ht_date">
                        {$res['sign_start_date']}~{$res['sign_end_date']}
                    </div>
                </div>
                <div class="form-item">
                    <div class="input-label"><span class="asterisk">*</span>发票编号|发票号码</div>
                    <div class="input-item">
                        <select name="invoice_id" id="invoice_id" class="form-control w200 required_select" autocomplete="off" required>
                            <option value="-10">请选择</option>
                            <foreach name="res['invoice']" item="vo">
                                <option value="{$vo.invoice_id}">{$vo.number}|{$vo.no}</option>
                            </foreach>
                        </select>
                        <span class="error-item">必填项</span>
                    </div>
                </div>
                <div class="form-item">
                    <div class="input-label">该发票编号开票金额</div>
                    <div class="input-item money_1">

                    </div>
                </div>
                <div class="form-item">
                    <div class="input-label">该发票编号已收款金额</div>
                    <div class="input-item money_2">

                    </div>
                </div>
                <div class="form-item">
                    <div class="input-label"><span class="asterisk">*</span>本次收款金额</div>
                    <div class="input-item money_3">

                    </div>
                </div>
                <div class="form-item">
                    <div class="input-label"><span class="asterisk">*</span>本次收款日期</div>
                    <div class="input-item">
                        <input type="text" name="date" value="{$today}" class="form-control Wdate w100 required_text"
                               onClick="WdatePicker()" readonly autocomplete="off">
                        <span class="error-item">必填项</span>
                    </div>
                </div>
                <div class="form-item">
                    <div class="input-label">备注</div>
                    <div class="input-item">
                        <textarea name="remark" class="form-control w400" autocomplete="off"></textarea>
                    </div>
                </div>
            </div>
            <div class="form-btn-item" id="submit"><input type="submit" value="提交" class="btn btn-submit">
                <button class="btn btn-default goback" type="button">返回</button>
            </div>
        </form>
    </div>
</div>
</body>
<include file="Include:javascript"/>
<script type="text/javascript">
    $(function () {
        /*编号联动*/
        $("[name='invoice_id']").change(function () {
            $('#submit').show();
            var val = $(this).val();
            if (val == -10) {
                $('.money_2,.money_1,.money_3').html('');
            } else {
                $('.money_3').html('');
                $.ajax({
                    type: "GET",
                    async: false,
                    dataType: "json",
                    data: {"invoice_id": val},
                    url: "__APP__/ContractBack/getSumMakeMoneyAndReceiptMoney",
                    success: function (data) {
                        $('.money_1').html(data.make_money);
                        $('.money_2').html(data.receipt_money_sum);
                        if (data.money > 0) {
                            $(".money_3").append(" <input value='" + data.money + "'max='" + data.money + "' type=\"number\" class=\"form-control required_text w100\" name=\"money\" required/>");
                        } else {
                            $('.money_3').html("<b>该发票已经全部收款完毕</b>");
                            $('#submit').hide();
                        }
                    }
                })
            }
        })
    });
    function verify() {
        var invoice_id = $("#invoice_id").val();
        if(invoice_id<0){
            defeated_alert('请选择发票编号');
            return false;
        }
    }
</script>
</html>